﻿using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Practices.ObjectBuilder;
using Microsoft.Practices.CompositeWeb;
using Microsoft.Practices.CompositeWeb.Utility;
using Common;

namespace ProjectDan.CRM.Views
{
    public class EditUploadedFilePresenter : Presenter<IEditUploadedFileView>
    {
        private ICRMController _controller;
        
        public EditUploadedFilePresenter([CreateNew] ICRMController controller)
        {
            _controller = controller;
        }

        public override void OnViewLoaded()
        {
            View.SaveUploadedFile += new EventHandler<DataEventArgs<UploadedFile>>(View_SaveUploadedFile);
        }

        void View_SaveUploadedFile(object sender, DataEventArgs<UploadedFile> e)
        {
            _controller.SaveUploadedFile(e.Data);
            View.CompleteSaveUploadedFile();
        }

        public override void OnViewInitialized()
        {
            View.Show(_controller.FindUploadedFileById(View.UploadedFileId));
        }

        public void ReleaseView()
        {
            View.SaveUploadedFile -= View_SaveUploadedFile;
        }
    }
}




